home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 466_01 / SRC / FMTTOPIC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  6.1 KB  |  296 lines

  1. #include <afx.h>
  2. #include <afxtempl.h>
  3. #include "parse.h"
  4. #include "input.h"
  5. #include "topiclog.h"
  6. #include "fmt.h"
  7. #include "fmtif.h"
  8. #include "fmttag.h"
  9. #include "fmtTopic.h"
  10. #include "errmsg.h"
  11.  
  12.  
  13. /******************************************************/
  14. // Tag list
  15. /******************************************************/
  16.  
  17. TAGSPEC gtagsTopicSection[] =
  18. {
  19.     CFmtListTopic::tagTag,              "tag",
  20.     CFmtListTopic::tagPre,            "pre",
  21.     CFmtListTopic::tagPost,           "post",
  22.     CFmtListTopic::tagIf,              "if",
  23.     CFmtListTopic::tagContext,         "context",
  24.     CFmtListTopic::tagTopicOrder,     "order",
  25.     CFmtListTopic::tagSrcParse,     "parsesource",
  26.     CFmtListTopic::tagSrcParse,     "parse",
  27.     -1,        NULL,
  28. };
  29.  
  30.  
  31. static TAGSPEC PARSETYPES[] = 
  32. {
  33.     CFmtTopic::parseFunc,          "function",
  34.     CFmtTopic::parseMfunc,         "memberfunction",
  35.     CFmtTopic::parseClass,         "class",
  36.     CFmtTopic::parseEnum,        "enum",
  37.     CFmtTopic::parseConstant,    "constant",
  38.     CFmtTopic::parseBsub,        "bsub",
  39.     CFmtTopic::parseBfunc,        "bfunc",
  40.     CFmtTopic::parseStruct,        "struct",
  41.     CFmtTopic::parseBtype,        "btype",
  42.     CFmtTopic::parseUnion,        "union",
  43.     -1,             NULL,
  44. };
  45.  
  46.  
  47.  
  48. /******************************************************/
  49. // Format class
  50. /******************************************************/
  51.  
  52. CFmtTopic::CFmtTopic(void) : CFmtTag(2)
  53. {
  54.     m_nSortWeight = 0;
  55.  
  56.     InitName(m_aNameTok, MAXTOPICNAMETOKENS);
  57.     InitName(m_aCtxTok, MAXTOPICNAMETOKENS);
  58.  
  59.     m_nNameTokens = 0;
  60.     m_nCtxTokens = 0;
  61.     m_nParseType = 0;
  62. }
  63.  
  64. CFmtTopic::~CFmtTopic(void)
  65. {
  66.     POSITION pos = m_listParaTags.GetHeadPosition();
  67.     while( pos != NULL)
  68.     {
  69.         delete m_listParaTags.GetNext(pos);
  70.     }
  71. }
  72.  
  73.  
  74. void CFmtTopic::PrintName(char *szNameBuf, CTag *ptag)
  75. {
  76.     ::PrintName(szNameBuf, m_aNameTok, m_nNameTokens, ptag, ptag);
  77. }
  78.  
  79. void CFmtTopic::PrintContext(char *szCtxBuf, CTag *ptag)
  80. {
  81.     if(m_nCtxTokens == 0)
  82.         PrintName(szCtxBuf, ptag);
  83.     else
  84.         ::PrintName(szCtxBuf, m_aCtxTok, m_nCtxTokens, ptag, ptag);
  85. }
  86.  
  87.  
  88.  
  89. #ifdef _DEBUG
  90. void CFmtTopic::Dump(CDumpContext &dc) const
  91. {
  92.     int i;
  93.  
  94.     CFmtTag::Dump(dc);
  95.  
  96.     dc << "\tsort weight: "<< m_nSortWeight << "; parse: ";
  97.     
  98.     for(i = 0; PARSETYPES[i].iTag != -1 && PARSETYPES[i].iTag != m_nParseType; i++);
  99.     
  100.     dc << PARSETYPES[i].szName << "\r\n";
  101.  
  102.     dc << "\ttag order: ";
  103.  
  104.     POSITION pos = m_listParaTags.GetHeadPosition();
  105.     while( pos != NULL)
  106.         dc << *m_listParaTags.GetNext(pos);
  107.  
  108.     dc << "\r\n";
  109. }
  110. #endif
  111.  
  112. /******************************************************/
  113. // List class
  114. /******************************************************/
  115.  
  116.  
  117.  
  118. TAGSPEC *CFmtListTopic::FmtTagList(void)
  119. {
  120.     return gtagsTopicSection;
  121. }
  122.     
  123.  
  124. int CFmtListTopic::ParseEntry(CFmtInput &in)
  125. {
  126. TRY
  127. {
  128.     int nRet;
  129.  
  130.     const char *sz1;
  131.     CFmtTopic *pNew;
  132.  
  133.     pNew = (CFmtTopic *)m_pNew;
  134.  
  135.     switch(m_nTag)
  136.     {
  137.     // Parent
  138.  
  139.     case tagTag:
  140.         
  141.         // Expect: .tag = name, output, fields, sortweight, nametemplate
  142.  
  143.         if(in.m_nTokens != 5)
  144.             return fmterrBadEntryCount;
  145.  
  146.         if(!CheckOutputType(in, 1))
  147.             return 0;
  148.  
  149.         nRet = CheckAddTag();
  150.         if(nRet)
  151.             return nRet;
  152.  
  153.         m_pNew = pNew = new CFmtTopic;
  154.  
  155.         m_nState.Tag = TRUE;
  156.  
  157.         // Record source file information.
  158.  
  159.         pNew->SetSource(in.m_nFile, in.m_lCurLine);
  160.  
  161.         // Get the required Name field.
  162.         
  163.         nRet = ParseName(pNew->m_sName, in.m_aszTokens[0]);
  164.         if(nRet)
  165.             return nRet;        
  166.  
  167.         // Get the required number of fields
  168.         
  169.         nRet = ParseNumFields(pNew->m_nNumFields, in.m_aszTokens[2]);
  170.         if(nRet)
  171.             return nRet;
  172.         
  173.         // Get the required sorting weight
  174.         
  175.         sz1 = EatWhite(in.m_aszTokens[3]);
  176.         if(! (isdigit(*sz1) || chHyphen == *sz1) )
  177.             return fmterrTopicExpectedSortWeight;
  178.             
  179.         MakeNumber(sz1, pNew->m_nSortWeight);
  180.         
  181.         // Get the required field name template
  182.         
  183.         sz1 = EatWhite(in.m_aszTokens[4]);
  184.         
  185.         nRet = ParseTopicNameMask(sz1, pNew->m_aNameTok, pNew->m_nNameTokens, 
  186.                                     pNew->m_nNumFields);
  187.            if(nRet)
  188.                return nRet;
  189.  
  190.         break;
  191.  
  192.     case tagContext:
  193.         if(m_nState.Skip)
  194.             return 0;
  195.  
  196.         if(!m_nState.Tag)
  197.             return fmterrOrphanedTag;
  198.  
  199.         if(in.m_nTokens != 1)
  200.             return fmterrBadEntryCount;
  201.  
  202.         ASSERT(m_pNew);
  203.  
  204.         sz1 = EatWhite(in.m_aszTokens[0]);
  205.  
  206.         nRet = ParseTopicNameMask(sz1, pNew->m_aCtxTok, pNew->m_nCtxTokens, 
  207.                                     pNew->m_nNumFields);
  208.            if(nRet)
  209.                return nRet;
  210.         
  211.         break;
  212.  
  213.     case tagTopicOrder:
  214.     {
  215.         static char szNameTerm[] = "\t ";
  216.         CString *p;
  217.         const char *sz2;
  218.         int i, j;
  219.  
  220.         if(m_nState.Skip)
  221.             return 0;
  222.  
  223.         if(!m_nState.Tag)
  224.             return fmterrOrphanedTag;
  225.  
  226.         if(in.m_nTokens == 0)
  227.             return fmterrBadEntryCount;
  228.  
  229.         ASSERT(m_pNew);
  230.  
  231.         for(j = 0; j < in.m_nTokens; j++)
  232.         {
  233.             for(i = 0, sz1 = EatWhite(in.m_aszTokens[j]);
  234.                 *sz1; 
  235.                 sz1 = EatWhite(++sz2))
  236.             {
  237.                 if(!isalpha(*sz1))
  238.                     return fmterrExpectedName;
  239.  
  240.                 sz2 = SeekEnd(sz1, szNameTerm, MAXTAGSIZE);
  241.                 if(sz2 == NULL)
  242.                     return fmterrBadTagName;
  243.  
  244.                 p = new CString(sz1, sz2-sz1);
  245.  
  246.                 pNew->m_listParaTags.AddTail(p);
  247.             }
  248.         }
  249.  
  250.         break;                
  251.     }
  252.             
  253.     case tagSrcParse:                    // Get the parsing type
  254.  
  255.         nRet = ParseSrcParse(pNew->m_nParseType, in, PARSETYPES);
  256.         if(nRet)
  257.             return nRet;
  258.  
  259.         break;
  260.     
  261.     case tagIf:
  262.         
  263.         nRet = ParseIf(*pNew, in);
  264.         if(nRet)
  265.            return nRet;
  266.  
  267.         break;
  268.  
  269.     // RTF file header and footer
  270.  
  271.     case tagPre:
  272.     case tagPost:
  273.  
  274.         // expect: .pre= format string
  275.  
  276.         nRet = SetFmtString(in, 0);
  277.  
  278.         if(nRet)
  279.             return nRet;
  280.         break;
  281.  
  282.     default:
  283.         return fmterrBadFmtEntry;
  284.     }
  285.  
  286.     return 0;
  287. }
  288. CATCH(CMemoryException, e)
  289. {
  290.     return errMemory;
  291. }
  292. END_CATCH
  293. }
  294.  
  295.  
  296.